package com.information.manage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.information.manage.basic.common.result.Result;
import com.information.manage.model.entity.ManuDO;
import com.information.manage.model.query.AddManuQuery;
import com.information.manage.model.query.ManuQuery;
import com.information.manage.model.query.UpdateManuQuery;
import com.information.manage.model.vo.StatisticDepartmentUploadVO;
import com.information.manage.service.ManuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "手动处理文章")
@RestController
@RequestMapping("/manu")
public class ManuController {

    @Autowired
    private ManuService manuService;

    @PostMapping("/add")
    @ApiOperation(value = "手动添加", notes = "手动添加")
    public Result<Long> add(HttpServletRequest request, @ModelAttribute AddManuQuery addManuQuery, @RequestParam(value = "enclosure", required = false) List<MultipartFile> enclosures){
        return manuService.add(addManuQuery, request, enclosures);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "修改")
    public Result<Boolean> updateAf(HttpServletRequest request, @ModelAttribute UpdateManuQuery updateManuQuery
            , @RequestParam(value = "enclosure", required = false) List<MultipartFile> enclosures){
        return manuService.updateAf(request, updateManuQuery, enclosures);
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除", notes = "删除")
    public Result<Boolean> delete(@RequestBody List<Long> ids){
        return manuService.delete(ids);
    }

    @GetMapping("/getFileEnclosurePath")
    @ApiOperation(value = "获取附件地址", notes = "获取附件地址")
    public Result<List<String>> getFileEnclosurePath(Long id){
        return manuService.getFileEnclosurePath(id);
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询", notes = "分页查询")
    public Result<Page<ManuDO>> findPage(HttpServletRequest request, ManuQuery manuQuery){
        return manuService.findPage(request, manuQuery);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation(value = "查询详情", notes = "查询详情")
    public Result<ManuDO> findById(@PathVariable("id") Long id){
        return Result.ok(manuService.findById(id));
    }

    @GetMapping("/statistic")
    @ApiOperation(value = "部门上传统计", notes = "部门上传统计")
    public Result<List<StatisticDepartmentUploadVO>> statisticDepartmentUpload(Integer days, Integer auditStatus){
        return manuService.statisticDepartmentUpload(days, auditStatus);
    }

}
